February 13, 2022
Create an example package
cd ~/robot_ws && mkdir src && cd src
ros2 pkg create --build-type ament_cmake my_project
Build a workspace in terminal and generate a compilation database
Let’s assume that only selected packages are built.
--packages-select
optioncd ..
colcon build --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja --symlink-install --packages-select my_project
colcon build
commandsCopy the commands into another file and modify them to the following:
#!/bin/zsh
source /opt/ros/humble/setup.zsh
source ~/robot_ws/install/local_setup.zsh
CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}:/opt/ros/humble /usr/bin/cmake ~/robot_ws/build/my_project -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_INSTALL_PREFIX=~/robot_ws/install/my_project
CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}:/opt/ros/humble /usr/bin/cmake --build ~/robot_ws/build/my_project -- -j23 -l23
CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}:/opt/ros/humble /usr/bin/cmake --install ~/robot_ws/build/my_project
.zsh
script. In our example, it is called cmake_commands.zsh
and placed into ~/robot_ws/build/my_project
.Make the script executable.
chmod +x cmake_commands.zsh
Set each item.
Build field: Click ’…’ icon to add an external.
Modify the configuration for build to the following:
Executable field: select binary file or script file.
example: ~/robotws/build/myproject/src/rundebugcommands.zsh
#!/bin/zsh
source /opt/ros/humble/setup.zsh
source ~/robot_ws/install/local_setup.zsh
~/robot_ws/build/manibot_bringup/joy_commander